/**
 * This class eats description of the unit cell as int[][] and returns appropriate Tuple[]
 */
package common;

/**
 * @author vladimir
 * 
 */
public class Neighbors {
	public int coordNumber = -1;
	int dimension = -1;
	public int[][][][] neighbors2;
	public int[][] neighbors1;
	int yDim = -1;
	int xDim = -1;

	public Neighbors(int[][] neighbors, int... args) {
		this.coordNumber = neighbors.length;// number of the neighbors
		this.dimension = neighbors[0].length;// dimensionality of the lattice

		this.xDim = args[0];
		if (args.length == 2) {
			this.yDim = args[1];
			this.neighbors2 = new int[this.xDim][this.yDim][this.coordNumber][this.dimension];
		}
		this.neighbors1 = new int[this.xDim][this.coordNumber];
		int tx = 0;
		int ty = 0;

		if (this.dimension == 2) {
			for (int x = 0; x < this.xDim; x++) {
				for (int y = 0; y < this.yDim; y++) {
					// fill neighbors array;
					for (int tn = 0; tn < this.coordNumber; tn++) {
						tx = x + neighbors[tn][0];
						if (tx == this.xDim) {
							tx = 0;
						} else if (tx == -1) {
							tx = this.xDim - 1;
						}
						ty = y + neighbors[tn][1];
						if (ty == this.yDim) {
							ty = 0;
						} else if (ty == -1) {
							ty = this.yDim - 1;
						}

						this.neighbors2[x][y][tn][0] = tx;
						this.neighbors2[x][y][tn][1] = ty;
					}
				}
			}
		} else if (dimension == 1) {
			for (int x = 0; x < this.xDim; x++) {
				// fill neighbors array;
				for (int tn = 0; tn < this.coordNumber; tn++) {
					tx = x + neighbors[tn][0];
					if (tx == this.xDim) {
						tx = 0;
					} else if (tx == -1) {
						tx = this.xDim - 1;
					}

					this.neighbors1[x][tn] = tx;
				}
			}
		}
	}

}
